<?php
class ChartsAnalysisAction extends IntesysAction{
	
    function _initialize(){
        parent::_initialize();
        $this->dao = D('Member');// 编辑、删除操作需要
    }
	public function index(){
		//不设置默认页
	} 
	//奖分和扣分统计,面积图，用来反映实时奖扣比例
	
	
	//个人月积分趋势图
	public function area(){
		$memberDB		=M('Member');
		$ayalysisDB		=D('Analysis');
		$integral_logDB =M('Integral_log');
		$integral_typeDB=M('Integral_type');
		$map['site_id'] =__SITEID__;
		
		//获取基本数据
		if($this->_param('memberpositionid')){
			$map['memberpositionid'] = array('like', '%,'.$this->_param('memberpositionid').',%');
			$member_id=$memberDB->where("memberpositionid like '%,".$this->_param('memberpositionid').",%'")->getField('id',true);
		}else if($this->_param('mid')){
			$member_id=$this->_param('mid');
		}else{
			$member_id=false;	
		}
		$chartType=$this->_param('chartType')?$this->_param('chartType'):'month';
		
		$map['typename']=$this->_param('integralType')?$this->_param('integralType'):'Binte';
		//判断图表时间
		switch($chartType){
			case 'year':
				$time=$ayalysisDB->$chartType();
				$chartType='chartYear';
			break;	
			case 'month':
				$time=$ayalysisDB->$chartType();
				$chartType='chart';
			break;	
			case 'week':
				$time=$ayalysisDB->$chartType();
				$chartType='chart';
			break;	
			default:
				$chartType='month';
				$time=$ayalysisDB->$chartType();
				$chartType='chart';
			break;	
		}
		//循环积分类型生成数据
		$integraltype = $integral_typeDB -> where($map) -> find();
		$map['type_id']=$integraltype['id'];
		$numType[]=['gt',0];
		$numType[]=['lt',0];
		foreach($numType as $v){
			$map['changenum']=$v;
			$list=$ayalysisDB->$chartType($member_id,$integraltype['id'],$time,$map);
			$arr[]=$list['arr'];
			$numSum[]=$list['sum'];
			$numCount[]=$list['count'];
		}
		//dump($arr);exit;
		//$form=$list['form'];
		$this->inteType=$integral_typeDB->where(['site_id'=>__SITEID__])->select();
		$this->numCount=$numCount;//abs(number_format($numCount[1]/$numCount[0],2))*100;
		$this->numSum=$numSum;//abs($numCount[1]).'/'.$numCount[0];
		$this->chartDate=$time['date'];
		//$this->chartForm=$form;
		$this->chartArr=$arr;
		$this->display();
	}

	public function arealist(){
		$memberDB		=M('Member');
		$ayalysisDB		=D('Analysis');
		$integral_logDB =M('Integral_log');
		$integral_typeDB=M('Integral_type');
		$map['site_id']=__SITEID__;
		
		//获取基本数据
		if($this->_param('memberpositionid')){
			$member_id=$memberDB->where("memberpositionid like '%,".$this->_param('memberpositionid').",%'")->getField('id',true);
		}else if($this->_param('member_id')){
			$member_id=$this->_param('member_id');
		}else{
			$member_id=false;	
		}
		$chartType=$this->_param('chartType')?$this->_param('chartType'):'month';
		
		$map['typename']=$this->_param('integralType')?$this->_param('integralType'):'Binte';
		//判断图表时间
		switch($chartType){
			case 'year':
				$time=$ayalysisDB->$chartType();
				$chartType='chartYear';
			break;	
			case 'month':
				$time=$ayalysisDB->$chartType();
				$chartType='chart';
			break;	
			case 'week':
				$time=$ayalysisDB->$chartType();
				$chartType='chart';
			break;	
			default:
				$chartType='month';
				$time=$ayalysisDB->$chartType();
				$chartType='chart';
			break;	
		}
		//循环积分类型生成数据
		$integraltype = $integral_typeDB -> where($map) -> find();
		$map['type_id']=$integraltype['id'];
		$numType[]=['gt',0];
		$numType[]=['lt',0];
		foreach($numType as $v){
			$map['changenum']=$v;
			$list=$ayalysisDB->$chartType($member_id,$integraltype['id'],$time,$map);
			$arr[]=$list['arr'];
			$date[]=$list['date'];
			$numSum[]=$list['sum'];
			$numCount[]=$list['count'];
		}
		//$form=$list['form'];
		$this->inteType=$integral_typeDB->where(['site_id'=>__SITEID__])->select();
		$this->numCount=$numCount;//abs(number_format($numCount[1]/$numCount[0],2))*100;
		$this->numSum=$numSum;//abs($numCount[1]).'/'.$numCount[0];
		$this->chartDate=$time['date'];
		//$this->chartForm=$form;
		$this->chartArr=$arr;
		$this->display();
	}
}